//
//  TF_PPTWKWebView.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/4/2.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit
import WebKit

class TF_PPTWKWebView: UIView {
    
    ///【字段含义】 类型  chat聊天    invite榜单  editor自定义图文      courseware课件     link自定义链接
    @objc public var type:NSString = ""
    @objc public let PPTView = UIView()
    //跳转链接
    @objc public var content:NSString = ""
    //自定义图文专用
    let webView = WKWebView()
    let urlimg = UIImageView()
    let urlLab = UILabel()


    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(self.webView)
    }
    @objc public func urlClick()

    {
        TalkfunSharedTools.openUrl(str: self.content)
     
    }
    @objc public func editorUI(msg:NSString)

    {
        var content:NSString = "<html><header><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'></header><body style='margin:0;padding:0'>" as NSString
        content = (content as String) + (msg as String) as NSString
        content = (content as String) + "</body></html>" as NSString
        
        content.addingPercentEscapes(using:String.Encoding.utf8.rawValue)


        self.webView.frame = self.bounds;
        self.webView.loadHTMLString(content as String, baseURL: nil)

    }
    @objc public func linkUI(content:NSString)

    {
        self.content = content;

        self.urlimg.image = UIImage.init(named: "HTLive.bundle/candanline")
        self.addSubview(self.urlimg)
        

        self.urlLab.textAlignment = .center;

        let sliderTap = UITapGestureRecognizer.init(target: self, action: #selector(urlClick))
        self.urlLab.addGestureRecognizer(sliderTap)
        

        self.urlLab.isUserInteractionEnabled = true
    
        let string = NSMutableAttributedString.getAttributed(string: "当前为超链接菜单，继续访问外部网页", font: UIFont.PingFang(size: 16), foregroundColor: UIColor(red: 23/255.0, green: 145/255.0, blue: 251/255.0, alpha: 1.0))
     
        string.addAttribute(.underlineStyle, value: NSNumber.init(integerLiteral: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, string.length))
        
        
        let attr1: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 19),.foregroundColor: UIColor(red: 65/255.0, green: 150/255.0, blue: 235/255.0, alpha: 1.0), ]
        string.addAttributes(attr1, range: NSMakeRange(0, string.length))
        

        self.urlLab.attributedText = string;
        self.addSubview(self.urlLab)
        
        self.urlimg.frame = CGRect(x: (self.frame.size.width-63.5)/2.0, y: 61.5, width: 63.5, height: 100)
    
        self.urlLab.frame = CGRect(x: 0, y: self.urlimg.frame.maxY+34, width: self.frame.width, height: 23)
        
    }
    //课件ui
    @objc public func coursewareUI()

    {
        //线
  
        self.PPTView.isUserInteractionEnabled = false
        self.PPTView.backgroundColor = UIColor.clear
        self.addSubview(self.PPTView)
        self.PPTView.frame = self.bounds;
    }
    override func layoutSubviews() {
        super.layoutSubviews()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
